from pydantic import BaseModel, Field
from typing import Optional


class RegisterUserIn(BaseModel):
    """注册 输入模型"""
    username: str = Field(..., max_length=50, min_length=3)
    password: str = Field(..., max_length=16, min_length=6)
    email: Optional[str] = Field(None, max_length=64)


class LoginUserIn(BaseModel):
    """登录 输入模型"""
    username: str = Field(..., max_length=50, min_length=3)
    password: str = Field(..., max_length=16, min_length=6)


class ProjectIn(BaseModel):
    project_name: str = Field(..., max_length=100)
    publish_app: Optional[str] = Field(None, max_length=100)
    project_desc: Optional[str] = Field(None, max_length=100)


class ProjectOut(BaseModel):
    id: int = Field(...)
    project_name: str = Field(..., max_length=100)
    publish_app: Optional[str] = Field(None, max_length=100)
    project_desc: Optional[str] = Field(None, max_length=100)
    user_id: int = Field(...)

    class Config:
        # 解析 sqlalchemy 的ORM对象
        orm_mode = True


class ProjectUpdateIn(BaseModel):
    """更新字段设置，三个都是可选"""
    project_name: Optional[str] = Field(None, max_length=100)
    publish_app: Optional[str] = Field(None, max_length=100)
    project_desc: Optional[str] = Field(None, max_length=100)


